package com.nit.lab.service.Impl;

import com.nit.lab.dao.HisOrderDao;
import com.nit.lab.dto.DtoOrderFile;
import com.nit.lab.dto.DtoSysFile;
import com.nit.lab.dto.DtohisOrder;
import com.nit.lab.dto.utils.DtoDataTable;
import com.nit.lab.service.HisOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by CYT on 2017/12/7.
 */
@Service
public class HisOrderServicelmpl implements HisOrderService {
    @Resource
    private HisOrderDao hisOrderDao;

    public HisOrderServicelmpl() {
        super();
    }

    @Override
    public Integer getHisOrderDataTableCount(String search, Integer pre, Integer actorId) throws Exception {
        Integer result = 0;
        try {
            result = this.hisOrderDao.getHisOrderDataTableCount(search, pre, actorId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<DtohisOrder> getHisOrderDataTable(DtoDataTable dtoDataTable, Integer pre, Integer actorId) throws Exception {
        List<DtohisOrder> result = new ArrayList<DtohisOrder>();
        result = hisOrderDao.getHisOrderDataTable(dtoDataTable.getStart(), dtoDataTable.getLength(), dtoDataTable.getSearch(), pre, actorId);
        for (DtohisOrder dtohisOrder : result
                ) {
            String[] listOrderFile = dtohisOrder.getOrderFiles().split(",");
            List<DtoOrderFile> dtoOrderFiles =new ArrayList<DtoOrderFile>();
            for (int i = 0; i < listOrderFile.length; i++) {
                dtoOrderFiles.add(hisOrderDao.getFileInfoByOrderId(Integer.parseInt(listOrderFile[i])));
            }
            dtohisOrder.setDtoOrderFiles(dtoOrderFiles);
        }
        return result;
    }

    @Override
    public Integer evaluate(Integer orderId, Integer evaluation) throws Exception {
        return hisOrderDao.insertEvaluate(orderId,evaluation);
    }
}
